﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Epona.Domain.Query.Impl
{
    public class CriteriaBuilder:ICriterionBuilder
    {
        public IQueryCriterion Eq(string propName, object value)
        {
            return new EqCriterion(propName, value);
        }

        public IQueryCriterion NotEq(string propName, object value)
        {
            return new NotEqCriterion(propName, value);
        }

        public IQueryCriterion Ge(string propName, IComparable value)
        {
            return new GeCriterion(propName, value);
        }

        public IQueryCriterion Gt(string propName, IComparable value)
        {
            return new GtCriterion(propName, value);
        }

        public IQueryCriterion Le(string propName, IComparable value)
        {
            return new LeCriterion(propName, value);
        }

        public IQueryCriterion Lt(string propName, IComparable value)
        {
            return new LtCriterion(propName, value);
        }

        public IQueryCriterion EqProp(string propName, string otherPropName)
        {
            return new EqPropCriterion(propName, otherPropName);
        }

        public IQueryCriterion NotEqProp(string propName, string otherPropName)
        {
            return new NotEqPropCriterion(propName, otherPropName);
        }

        public IQueryCriterion GtProp(string propName, string otherPropName)
        {
            return new GtPropCriterion(propName, otherPropName);
        }

        public IQueryCriterion GeProp(string propName, string otherPropName)
        {
            return new GePropCriterion(propName, otherPropName);
        }

        public IQueryCriterion LtProp(string propName, string otherPropName)
        {
            return new LtPropCriterion(propName, otherPropName);
        }

        public IQueryCriterion LeProp(string propName, string otherPropName)
        {
            return new LePropCriterion(propName, otherPropName);
        }

        public IQueryCriterion SizeEq(string propName, int size)
        {
            return new SizeEqCriterion(propName, size);
        }

        public IQueryCriterion SizeNotEq(string propName, int size)
        {
            return new SizeNotEqCriterion(propName, size);
        }

        public IQueryCriterion SizeGe(string propName, int size)
        {
            return new SizeGeCriterion(propName, size);
        }

        public IQueryCriterion SizeGt(string propName, int size)
        {
            return new SizeGtCriterion(propName, size); 
        }

        public IQueryCriterion SizeLe(string propName, int size)
        {
            return new SizeLeCriterion(propName, size);
        }

        public IQueryCriterion SizeLt(string propName, int size)
        {
            return new SizeLtCriterion(propName, size);
        }

        public IQueryCriterion ContainsText(string propName, string value)
        {
            return new ContainsTextCriterion(propName, value);
        }

        public IQueryCriterion StartsWithText(string propName, string value)
        {
            return new StartsWithTextCriterion(propName, value);
        }

        public IQueryCriterion In(string propName, System.Collections.ICollection value)
        {
            return new InCriterion(propName, value);
        }

        public IQueryCriterion In(string propName, object[] value)
        {
            return new InCriterion(propName, value);
        }

        public IQueryCriterion NotIn(string propName, System.Collections.ICollection value)
        {
            return new NotInCriterion(propName, value);
        }

        public IQueryCriterion NotIn(string propName, object[] value)
        {
            return new NotInCriterion(propName, value);
        }

        public IQueryCriterion Between(string propName, IComparable from, IComparable to)
        {
            return new BetweenCriterion(propName, from, to);
        }

        public IQueryCriterion IsNull(string propName)
        {
            return new IsNullCriterion(propName);
        }

        public IQueryCriterion NotNull(string propName)
        {
            return new NotNullCriterion(propName);
        }

        public IQueryCriterion IsEmpty(string propName)
        {
            return new IsEmptyCriterion(propName);
        }

        public IQueryCriterion NotEmpty(string propName)
        {
            return new NotEmptyCriterion(propName);
        }

        public IQueryCriterion Not(IQueryCriterion criterion)
        {
            return new NotCriterion(criterion);
        }

        public IQueryCriterion And(params IQueryCriterion[] criterions)
        {
            return new AndCriterion(criterions);
        }

        public IQueryCriterion Or(params IQueryCriterion[] criterions)
        {
            return new OrCriterion(criterions);
        }

        public IQueryCriterion IsTrue(string propName)
        {
            return Eq(propName, true);
        }

        public IQueryCriterion IsFalse(string propName)
        {
            return Eq(propName, false);
        }

        public IQueryCriterion IsBlank(string propName)
        {
            return Or(IsNull(propName), Eq(propName, ""));
        }

        public IQueryCriterion NotBlank(string propName)
        {
            return And(NotNull(propName), NotEq(propName, ""));
        }

        public IQueryCriterion Empty()
        {
            return new EmptyCriterion();
        }
    }
}
